import React, { Component } from 'react';
import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Image,
    Navigator,
    WebView,TextInput,DeviceEventEmitter
} from 'react-native';
import NavigationBar from './js/common/NavigationBar'
import GitHubTrending from 'GitHubTrending'
const URL = 'https://github.com/trending/'
export default class TrendingTest extends Component {
    constructor(props) {
        super(props)
        this.trending = new GitHubTrending()
        this.state={
            result: null
        }
    }
    onLoad() {
        let url = URL + this.text
        this.trending.fetchTrending(url)
            .then(result => {
                this.setState({
                    result: JSON.stringify(result)
                })
            })
            .catch(e=>{
                this.setState({
                    result: JSON.stringify(e)
                })
            })
    }
    render() {
        return (
            <View style={styles.container}>
                <NavigationBar
                    title={'TredingTest使用'}
                />
                <View style={styles.row}>
                    <Text style={styles.tips} onPress={()=>this.onLoad()}>返回</Text>
                    <TextInput style={styles.input} onChangeText={text=>this.text=text}/>
                </View>
                <Text style={{flex: 1}}>{this.state.result}</Text>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'red',
        justifyContent: 'center'
    },
    text: {
        fontSize: 20
    },
    tips: {
        fontSize: 20
    },
    row: {
        flexDirection: 'row',
        alignItems: 'center',
        margin: 10
    },
    input: {
        height: 40,
        flex: 1,
        borderWidth: 1,
        margin: 2
    }
});